package com.ruoyi.comment.controller;

import com.ruoyi.comment.domain.Evaluation;
import com.ruoyi.comment.service.IEvaluationService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 测评表管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/comment/evaluation")
public class EvaluationController extends BaseController
{
    @Autowired
    private IEvaluationService evaluationService;

    /**
     * 查询测评表管理列表
     */
    @PreAuthorize("@ss.hasPermi('comment:evaluation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Evaluation evaluation)
    {
        startPage();
        List<Evaluation> list = evaluationService.selectEvaluationList(evaluation);
        return getDataTable(list);
    }

    /**
     * 导出测评表管理列表
     */
    @PreAuthorize("@ss.hasPermi('comment:evaluation:export')")
    @Log(title = "测评表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Evaluation evaluation)
    {
        List<Evaluation> list = evaluationService.selectEvaluationList(evaluation);
        ExcelUtil<Evaluation> util = new ExcelUtil<Evaluation>(Evaluation.class);
        util.exportExcel(response, list, "测评表管理数据");
    }

    /**
     * 获取测评表管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:evaluation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Evaluation evaluation = evaluationService.selectEvaluationById(id);
        // 无需手动查询 themes，MyBatis 已通过 <collection> 自动加载
        return AjaxResult.success(evaluation);
    }

    /**
     * 新增测评表管理
     */
    @PreAuthorize("@ss.hasPermi('comment:evaluation:add')")
    @Log(title = "测评表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Evaluation evaluation)
    {
        return toAjax(evaluationService.insertEvaluation(evaluation));
    }

    /**
     * 修改测评表管理
     */
    @PreAuthorize("@ss.hasPermi('comment:evaluation:edit')")
    @Log(title = "测评表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Evaluation evaluation)
    {
        return toAjax(evaluationService.updateEvaluation(evaluation));
    }

    /**
     * 删除测评表管理
     */
    @PreAuthorize("@ss.hasPermi('comment:evaluation:remove')")
    @Log(title = "测评表管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(evaluationService.deleteEvaluationByIds(ids));
    }
}
